<?php
include_once('../home/config.php');
include_once("inc/facebook.php"); //include facebook SDK
######### edit details ##########
$appId = '447585838689244'; //Facebook App ID
$appSecret = '656daea5a728be928c800464f9b279e4'; // Facebook App Secret
$fbPermissions = 'publish_stream,manage_pages';  //Required facebook permissions
##################################
$return_url = 'http://localhost:8888/auto_facebook'; 
$url_first_login = 'http://localhost:8888/auto_facebook';
//Call Facebook API
$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $appSecret,
  'cookie' => true
));

// Set access token
$access_token = 'CAAGXE7Lr69wBAJlkWPDbpZBv2HMZA3G4SDSmLSuKDHDucUKbtQsgXozrNTqKGOWlgGBOgPzhIDeAM0vLXlEQbZBr8B42owTxRBVpDsUL0pBiwfYW6FNvu6PyZBJOJAKVSmPSY7A7ffrJPL3yuCn1jTGs4ZAZACP63WlAUENvPd1QQop1h3Mjsq';
$facebook->setAccessToken($access_token);
$fbuser = $facebook->getUser();
$userPageId = '531528536900313';
// Get link, title,.. post facebook
$db_new_post = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,new_hot_home,new_relate,new_tags,new_cat_id,
                                    cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE 1 AND new_hot_home = 1
                                ORDER BY new_date DESC 
                                LIMIT 1');
// Get time last post facebook
//$db_last_post = new db_query('SELECT MAX(post_last_facebook) AS last_post FROM posts WHERE post_active = 1');
//$max_post = $db_last_post->resultArray();
$row = mysql_fetch_assoc($db_new_post->result);

   $title         = $row['new_title'];
   $description   = $row['new_teaser'] != '' ? cut_string(removeHTML($row['new_teaser']),150) : cut_string(removeHTML($row['new_detail']),150);
   //echo $row['post_content'];
   $picture       = $row['new_picture']; 
   $id_post       = $row['new_id'];
   $idcat_post    = $row['new_cat_id'];
   $ncat_post     = $row['cat_name'];
   
// create link post facebook
$link = 'http://vnupdate.net'.generate_detail_url($row);
// Image link post facebbok
?>